import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import store from '../store/index'
// import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes: Array<RouteConfig> = [
  // {
  //   path: '/',
  //   name: 'Home',
  //   component: Home
  // },
  {
    path: '/',
    name: 'Login',
    component: () => import('../views/login/login.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/login.vue')
  },
  {
    path: '/personalInformation',
    name: 'PersonalInformation',
    component: () => import('../views/personalInformation/personalInformation.vue')
  },
  {
    path: '/questionnaire',
    name: 'Questionnaire',
    component: () => import('../views/questionnaire/questionnaire.vue')
  },
  {
    path: '/visitorRegistration',
    name: 'VisitorRegistration',
    component: () => import('../views/visitorRegistration/visitorRegistration.vue')
  },
  {
    path: '/confirmation',
    name: 'Confirmation',
    component: () => import('../views/confirmation/confirmation.vue')
  },


]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {

  if (!store.getters.user.mobile) {
    if (to.name !== "Login") {
      router.push('/login')
    }else{
      next()
    }
  
  } else {
    if (from.name !== 'PersonalInformation' && to.name == "Login") {
      router.push('/personalInformation')
      return
    }
    next()
  }
})

export default router
